<script setup lang="ts">
import { GetNameList } from '@/api/unit/unit'
import { propTypes } from '@/utils/propTypes'
import { ref, watch } from 'vue'

const deptName = ref<String[]>([])
const props = defineProps({
  deptId: propTypes.any
})
const loadName = async (keys) => {
  if (!Array.isArray(keys)) {
    keys = [keys]
  }
  deptName.value = await GetNameList(keys)
}
watch(
  () => props.deptId,
  (val: string) => {
    if (val && val.length > 0) {
      loadName(val)
    } else {
      deptName.value = []
    }
  },
  {
    immediate: true
  }
)
</script>

<template>
  <el-space v-if="deptName.length > 0">
    <span v-for="(i, index) in deptName" :key="index">{{ i }}</span>
  </el-space>
</template>
